<?php


namespace app\staff\controller;

use app\common\service\Wechat;
use think\Db;

class Login extends Common
{
    public function getIndex()
    {
        $oWechat = new Wechat();
        $path = $oWechat->qrWxcode();
        $data['logo'] = request()->domain() . $path;
        return $this->success('数据获取成功', $data);
    }

    public function doLogin()
    {
        $username = input('username');
        if (!$username) {
            return $this->error('请输入账号');
        }
        $password = input('password');
        if (!$password) {
            return $this->error('请输入密码');
        }
        $data = Db::name('staff')->where('username', $username)->find();
        if (!$data) {
            return $this->error('账号不存在');
        }
        if (md5($password) != $data['password']) {
            return $this->error('密码错误');
        }
        return $this->success('ok', [
            'token' => $data['id']
        ]);
    }
}
